<!-- 订单管理 -->

<template>
  <div class="page-box h100 display-flex czbj">
    <div class="n-card-header__main pm10">
      所有订单列表
    </div>
    <div>
      <dxtable :czFun="czFun" :pageSize="30" :headBtn="headBtn" :dataJson="dataJson" :portUrl="portUrl" :qx="qx"
        ref="databale" sonRouter="hhdetails" delurl="hhscdd/orderMeg/delorderMaterial" @handleSorterChange="handleSorterChange">
      </dxtable>
    </div>
  </div>
</template>
<script lang="ts">
export default {
  name: "hhorderManagementList",
};
</script>
<script lang='ts' setup>
import dxtable from "../../../components/util/dxtable.vue";
import sort from "../../../components/util/sort.vue";
import { dxget, dxpost, qurl, hf,transferTimeseer } from "../../../util/index";
import { h, ref, reactive,onBeforeUpdate } from "vue";
import { NButton, NTime } from "naive-ui";
const props = defineProps({
  pup: { type: String },
});
const fusd = (row) => {
  const hredsd = window.location.href
  const text = hredsd.split("#/")[0] + `#/hhdetails?id=${row.order_id}&type=3&ck=3`
  navigator.clipboard.writeText(text);
  window.$message.success("复制成功")
}
let headBtn = [];
const zdList = ref()
const databale = ref();
const initeer = () => {
  databale.value.initDataExpose();
};
const taskListref = ref()
onBeforeUpdate(() => {
  try {
    initeer()
  } catch (e) {

  }
})

const format = 'yyyy年MM月dd日'
const emit = defineEmits(["callBack"]);
// 弹窗公用该列表
let dataJson = reactive([
  {
    title: "客户代码",
    search: true, // 是否在搜索栏展示
    key: "client_code",
    width: 80,
  },
  {
    title: "订单编号",
    key: "order_num",
    search: true, // 是否在搜索栏展示
    width: 120,
    render(row) {
      return h('span', {
        class: "ls sz", onClick: () => {
          fusd(row)
        }
      }, row.order_num)
    }
  }, {
    title: "订单日期",
    key: "date",
    type: "daterange",
    search: true, // 是否在搜索栏展示
    sorter: 'default',
    width: 120,
    render(row) {
      return transferTimeseer(row.date)
    }
  }, {
    title: "物料代码",
    search: true, // 是否在搜索栏展示
    key: "material_code",
  }, {
    title: "品名",
    search: true, // 是否在搜索栏展示
    key: "type_name",
  }, {
    title: "订单数量(件)",
    key: "order_sum",
    width: 60
  },

  {
    title: "完工数量",
    key: "start_finish_quantity",
    width: 60,
    render(row) {
      if (row.start_finish_quantity) {
        return row.start_finish_quantity
      }
      return '--'
    }
  },

  {
    title: "发货数量",
    key: "sent_sum",
    width: 60,
    render(row) {
      return row.sent_sum || '--'
    }

  },




  {
    title: "工序",
    key: "processes",
    render(row) {
      try {
        const jjmer = []
        row.gxList.map(a => {
          jjmer.push({
            process_code: a.process_code,
            status: a.status
          })
        })
        const lijser = []
        jjmer.map((a, b) => {
          let syjer = ''
          if (b < jjmer.length - 1) {
            syjer = '--'
          }
          let clsdwe = ""

          if (a.status == 1) {
            clsdwe = "hye"
          }
          if (a.status == 2) {
            clsdwe = "ls"
          }
          lijser.push(h('span', { class: clsdwe + ' kkmsdasrer' }, a.process_code + syjer))
        })

        return h("div", { class: "jjmlxert" }, lijser)

      } catch (e) {
        return '--'
      }


    }
  }, {
    title: "完成品交期",
    key: "commit_date",
    type: "daterange",
    search: true, // 是否在搜索栏展示
    width: 120,
    sorter: 'default',
    render(row) {
      let jnser = row.commit_date
      const currenTime = new Date().getTime()
      const commitdate = new Date(jnser).getTime()
      let maxsd = commitdate - currenTime
      let siurwef = transferTimeseer(jnser)  
      if (row.is_sent == 2) {
        return siurwef
      }
      if (maxsd < 0) {
        row.yuqis = true
        return h("div", { class: "bgred" }, siurwef)
      }
      if (maxsd < (1000 * 60 * 60 * 24 * 3)) {
        return h("div", { class: "bgyed" }, siurwef)
      }

      return siurwef
    }
  },
  // {
  //   title: "订单状态",
  //   key: "",
  //   width: 80,
  //   render(row) {
  //     return row.status == 2 ? '已完成' : "未完成"
  //   }
  // },
  // {
  //     title: "状态",
  //     key: "",
  //     render(row){
  //         return row.status==0?'未完成':"已完成"
  //     }
  // },
  {
    title: "发货状态",
    key: "is_sent",
    width: 130,
    render(row) {
      let jnxer = '未发货'
      if(row.is_sent==2){
        jnxer = '已发货:'+transferTimeseer(row.delivery_time)
      }
      return jnxer
    }
  },
  {
    title: "发货人",
    key: "real_name",
    width: 90,
    render(row) {
      return row.real_name || '--'
    }
  },
  {
    title: "是否逾期",
    width: 80,
    key: "",
    fixed: 'left',
    render(row) {
      if(row.yuqis){

        return '是'
      }
      // 实际完工日期> 交工日期
      return row.real_finish_date > row.commit_date ? '是' : '否'
    }

  },
]);
let portUrl = "hhscdd/orderMeg/getodList";
const handleSorterChange = (data)=>{
  console.log(data);
  if(data.data.columnKey=="commit_date"){
    if(!data.data.order){
      data.parameters.sortsx = ''
    }
    if(data.data.order=="descend"){
      data.parameters.sortsx = 'order_material.commit_date DESC'
    }
    if(data.data.order=="ascend"){
      data.parameters.sortsx = 'order_material.commit_date ASC'
    }
      
  }
  if(data.data.columnKey=="date"){
    if(!data.data.order){
      data.parameters.sortsx = ''
    }
    if(data.data.order=="descend"){
      data.parameters.sortsx = 'mould_order.date DESC'
    }
    if(data.data.order=="ascend"){
      data.parameters.sortsx = 'mould_order.date ASC'
    }
      
  }
  initeer()
}
const qx = {
  DeletePermissionID: "hhorderManagementListdel", //删除
  EditPermissionIdentifier: "hhorderManagementListbj", // 编辑
  NewPermissionIdentifier: "hhorderManagementListxz", // 新建
  ViewPermissionID: "hhorderManagementListck", // 查看
};

const czFun = {
  fun: (row) => {
    return h(
      NButton,
      {
        type: "info",
        quaternary: true,
        onClick: async (e) => {
          hf("hhdetails", { id: row.order_id, type: 3 });
        },
      },
      "详情"
    );
  },
};
</script>
  
  